from os import path
from pathlib import Path
import shutil
import random

work_dir = Path('F:/python/python_work/temp')
start_dir =Path('a/b/c/d')
(work_dir / start_dir ).mkdir(parents=True,exist_ok=True)
touch_dir = list(start_dir.parents)[:-1] + [start_dir]
#print(touch_dir)

filenames =(''.join(random.choices('abcdefghijklmnopqrstuvwxyz', k=4)) for i in range(50))
#print(type(filenames),filenames)

for filename in filenames:
    (work_dir / random.choice(touch_dir) / filename).touch()

src = work_dir/'a'
#print(type(src),src)
dst = work_dir/'dst'
#
def ignore(src,names):

    return {name for name in names if name[0] not in list('xyz') and Path(src,name).is_file()} # 这里的'xyz'没必要用列表再转一下，


shutil.copytree(src, dst, ignore = ignore)
